var Log = require('../framework/log');
var Player = require('../core/player');

function LoginHandler(session,msg){
    var player = new Player();
    player.name = msg.playerId;
    player.hp = 100;
    player.wuli = Math.floor(Math.random()*100) + 1;
    player.swordLevel = Math.floor(Math.random()*3) + 1;
    player.ownCards = {
        'attack':true,
        'iron-force':true
    };
    player.exp = 0;
    player.id = msg.playerId;
    player.win = Math.floor(Math.random()*1000) + 1;
    player.lost = Math.floor(Math.random()*1000) + 1;
    player.drop = Math.floor(Math.random()*100) + 1;
    player.faceId = 'face_1';
    session.attachPlayer(player);
    player.setSession(session);
    app.getChannelService().enterChannel("world",player);
    var playerData = {};

    playerData.id = player.id;
    playerData.name = player.name;
    playerData.hp = player.hp;
    playerData.wuli = player.wuli;
    playerData.swordLevel = player.swordLevel;
    playerData.ownCards = player.ownCards;
    playerData.exp = player.exp;
    playerData.money = player.money;
    playerData.win = player.win;
    playerData.lost = player.lost;
    playerData.drop = player.drop;
    playerData.faceId = player.faceId

    Log.debug("LoginHandler OK,player = %s",player.id);
    return {ret:true,"playerData":playerData};
}


module.exports = LoginHandler;